<?php

class Member_model extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->table = 'member';
    }
    function getSearch($params, $sort = 'id', $order = 'asc') {
    	$this->db->select('member.*');
    	if ($params['full_name'] != '') {
    		$this->db->where("(member.first_name LIKE '%".$params['full_name']."%' OR last_name LIKE '%".$params['full_name']."%' OR email LIKE '%".$params['full_name']."%')");
    	}
    	if ($params['gender_value'] != '') {
    		$this->db->where('gender', $params['gender_value']);
    	}
    	if ($params['owner_id'] != '') {
    		$this->db->where('member.owner', $params['owner_id']);
    	}
    	$this->db->order_by('member.' . $sort, $order);
    	$this->db->order_by('member.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function getOwner( $sort = 'id', $order = 'asc') {
    	$this->db->select('member.id, member.first_name, member.last_name');
    	$this->db->where('member.owner', 0);
    	$this->db->order_by('member.' . $sort, $order);
    	$this->db->order_by('member.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function getAll( $sort = 'id', $order = 'asc') {
    	$this->db->select('member.id, member.first_name, member.last_name');
    	$this->db->where('member.status', 0);
    	$this->db->order_by('member.' . $sort, $order);
    	$this->db->order_by('member.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function getAllByOwner($owner_id, $sort = 'id', $order = 'asc') {
    	$this->db->select('member.id, member.first_name, member.last_name, member.facebookid, member.gender, member.insertion, member.address, member.house_number,member.postcode, member.place, member.email, member.phone, member.birthday, member.owner, member.death ');
    	$this->db->where('member.status', 0);
    	$this->db->where('member.owner',$owner_id);
    	$this->db->order_by('member.' . $sort, $order);
    	$this->db->order_by('member.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function getName($member_id){
    	$this->db->select('member.id,member.first_name, member.last_name');
    	$this->db->where('member.id', $member_id);
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function login($email, $pass){
    	$this->db->select('member.id');
    	$this->db->where('member.email', $email);
    	$this->db->where('member.password', $pass);
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function loginWithFace($faceId){
    	$this->db->select('member.id');
    	$this->db->where('member.facebookid', $faceId);
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
}

?>
